{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6299add3",
   "metadata": {},
   "source": [
    "# Tensorflow工程师职场实战技第8课书面作业\n",
    "\n",
    "学号：114764\n",
    "\n",
    "**作业内容：**  \n",
    "https://github.com/DeepRNN/image_captioning\n",
    "\n",
    "这是论文《Show, Attend and Tell: Neural Image Caption Generation with Visual Attention》的实现，尝试对比这个模型和课上所讲的模型，对于不同图片的测试结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bee1494",
   "metadata": {},
   "source": [
    "我选择对比如下两种模型(都是基于tensorflow 2.x的)：  \n",
    "1. keras的官方样例：https://keras.io/examples/vision/image_captioning/ ，下面称之**模型1**  \n",
    "2. 对于https://github.com/DeepRNN/image_captioning 的tensorflow 2.x实现：https://github.com/Abdalrahman112/Image-captioning ，下面称之**模型2**  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bc98d76",
   "metadata": {},
   "source": [
    "对比上述两个实现及其模型和结果，非常有代表性：因为**模型1**是基于Transformer模型来实现的，**模型2**是RNN+Attention结构的。我将对比一下两者的模型差异。 然后对比一下**模型1**与**模型2**对不同图片的测试结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8527648",
   "metadata": {},
   "source": [
    "不过，**模型1**采用的训练集是Flicker8k_Dataset，**模型2**采用的是微软的COCO2014。我将**模型1**修改适配到训练MS COCO2014数据集上，"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a260ae1b",
   "metadata": {},
   "source": [
    "**模型1**的结构图大致如下：  \n",
    "![tensor08_model2](https://gitee.com/dotzhen/cloud-notes/raw/master/tensor08_model2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c9acb038",
   "metadata": {},
   "source": [
    "**模型2**的结构图大致如下：  \n",
    "![tensor08_model1](https://gitee.com/dotzhen/cloud-notes/raw/master/tensor08_model1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec6810d4",
   "metadata": {},
   "source": [
    "两个模型的比较本质是Transformer模型与RNN+Attention模型的比较。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a49b3b7",
   "metadata": {},
   "source": [
    "实测对于不同图片的结果如下。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13520846",
   "metadata": {},
   "source": [
    "**模型1结果**：\n",
    "![tensor08-1](https://gitee.com/dotzhen/cloud-notes/raw/master/tensor08-1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aea4c63d",
   "metadata": {},
   "source": [
    "**模型2结果：**\n",
    "![tensor08-2](https://gitee.com/dotzhen/cloud-notes/raw/master/tensor08-2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af222832",
   "metadata": {},
   "source": [
    "从结果看，模型1要优于模型2。  \n",
    "模型1源代码：https://gitee.com/dotzhen/tensorflow-practical-skills/blob/master/class08/image_caption_with_transformer.ipynb  \n",
    "模型2源代码：https://gitee.com/dotzhen/tensorflow-practical-skills/blob/master/class08/image_captioning_with_LSTM_Attention.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "926f6bac",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
